﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DieuKhien;
using ThucThe;

namespace GiaoDien
{
    public partial class NV : Form
    {
        public NV()
        {
            InitializeComponent();
        }
        KhachHang_thucthe khs_tt = new KhachHang_thucthe();
        private void buttonX7_Click(object sender, EventArgs e)
        {
            KhachHang_dieukhien kh_dk = new KhachHang_dieukhien();
            KhachHang_thucthe kh_tt = new KhachHang_thucthe();
            kh_tt.TenKhachHang = txt_timKhachHang.Text.Trim();
            kh_dk.TimKhachHang(kh_tt);
        }
        private void buttonX27_Click(object sender, EventArgs e)
        {
            //this.Close();
            NV_KhachHang_frm kh = new NV_KhachHang_frm();
            kh.ShowDialog();
            NV_Load(sender, e);
        }

        private void buttonX21_Click(object sender, EventArgs e)
        {
            NV_KhachHang_sua kh = new NV_KhachHang_sua();
            kh.loadKhachHang(khs_tt);
            kh.ShowDialog();
            NV_Load(sender, e);
        }
        private void tbl_KhachHang_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;
            if (dong >= 0 & dong < (tbl_KhachHang.RowCount - 1))
            {
                khs_tt.MaKhachHang = int.Parse(tbl_KhachHang.Rows[dong].Cells[0].Value.ToString());
                khs_tt.TenKhachHang = tbl_KhachHang.Rows[dong].Cells[1].Value.ToString();
                khs_tt.NgaySinh = tbl_KhachHang.Rows[dong].Cells[2].Value.ToString();
                khs_tt.GioiTinh = Convert.ToBoolean(tbl_KhachHang.Rows[dong].Cells[3].Value);
                khs_tt.Sdt = tbl_KhachHang.Rows[dong].Cells[4].Value.ToString();
                khs_tt.DiaChi = tbl_KhachHang.Rows[dong].Cells[6].Value.ToString();
                khs_tt.Email = tbl_KhachHang.Rows[dong].Cells[5].Value.ToString();
            }
        }
        private void buttonX6_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn chắc chắn muốn xóa ?", "Khách hàng", MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
            {
                KhachHang_thucthe kh_tt = new KhachHang_thucthe();
                KhachHang_dieukhien kh_dk = new KhachHang_dieukhien();
                kh_tt.MaKhachHang = int.Parse(tbl_KhachHang.CurrentRow.Cells[0].Value.ToString());
                kh_dk.XoaKhachHang(kh_tt);
                if ( kh_dk.XoaKhachHang(kh_tt) == 1)
                {
                    MessageBox.Show("Xóa thành công");
                    NV_Load(sender, e);
                }
            }
                
        }

        private void buttonX5_Click(object sender, EventArgs e)
        {
            NV_HopDong frm_themHD = new NV_HopDong();
            frm_themHD.ShowDialog();
            frm_themHD.load_HopdDong(khs_tt);
            NV_Load(sender, e);
        }
        private void buttonX1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        // //////////////////////////////////////////////////////////////////////Hop Dong
        HopDong_thucthe hds_tt = new HopDong_thucthe();
        KhachHang_thucthe khss_tt = new KhachHang_thucthe();
        NhanVien_thucthe nvs_tt = new NhanVien_thucthe();
        Tour_thucthe tours_tt = new Tour_thucthe();
        private void buttonX28_Click(object sender, EventArgs e)
        {
            NV_HopDong hd = new NV_HopDong();
            hd.ShowDialog();
            NV_Load(sender, e);
        }

        private void buttonX13_Click(object sender, EventArgs e)
        {
            NV_HopDong_sua frm_hd_sua = new NV_HopDong_sua();
            frm_hd_sua.ShowDialog();
            frm_hd_sua.loadHopDong(hds_tt, khss_tt, nvs_tt, tours_tt);
            NV_Load(sender, e);
        }

        private void buttonX12_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn chắc chắn muốn xóa ?", "Hợp đồng", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                HopDong_dieukhien hd_dk = new HopDong_dieukhien();
                HopDong_thucthe hd_tt = new HopDong_thucthe();
                hd_tt.MaHopDong = int.Parse(tbl_HopDong.CurrentRow.Cells[0].Value.ToString());
                hd_dk.xoaHopdong(hd_tt);
                int kq = hd_dk.xoaHopdong(hd_tt);
                if (kq > 0)
                {
                    MessageBox.Show("Xóa thành công");
                }
            } 
        }


        private void buttonX2_Click(object sender, EventArgs e)
        {
            HopDong_dieukhien hd_dk = new HopDong_dieukhien();
            HopDong_thucthe hd_tt = new HopDong_thucthe();
            KhachHang_thucthe kh_tt = new KhachHang_thucthe();
            kh_tt.TenKhachHang = txt_timHopDong.Text.Trim();
            hd_dk.timHopDong(kh_tt); 

        }

        private void tbl_HopDong_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;
            if (dong > 0 && dong < (tbl_HopDong.RowCount - 1))
            {
                hds_tt.MaHopDong = int.Parse(tbl_HopDong.Rows[dong].Cells[0].Value.ToString());
                hds_tt.MaKhachHang = int.Parse(tbl_HopDong.Rows[dong].Cells[1].Value.ToString());
                khss_tt.TenKhachHang = tbl_HopDong.Rows[dong].Cells[2].Value.ToString();
                hds_tt.MaNhanVien = int.Parse(tbl_HopDong.Rows[dong].Cells[3].Value.ToString());
                nvs_tt.TenNhanVien = tbl_HopDong.Rows[dong].Cells[4].Value.ToString();
                hds_tt.MaTour = tbl_HopDong.Rows[dong].Cells[5].Value.ToString().Trim();
                tours_tt.TenTour = tbl_HopDong.Rows[dong].Cells[6].Value.ToString();
                hds_tt.NgayTao = tbl_HopDong.Rows[dong].Cells[7].Value.ToString();
            }
        }
        // //////////////////////////////////////////////////////////////////////////////////VE

        private void buttonX33_Click(object sender, EventArgs e)
        {
            try
            {

                Ve_dieukhien ve_dk = new Ve_dieukhien();
                Ve_thucthe ve_tt = new Ve_thucthe();
                ve_tt.MaHopDong = int.Parse(cbo_maHopDong.Text);
                ve_dk.themVe(ve_tt);
                MessageBox.Show("Thêm thành công");
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Chọn mã hợp đồng");
            }
        }
        private void buttonX20_Click(object sender, EventArgs e)
        {
            try
            {

                Ve_dieukhien ve_dk = new Ve_dieukhien();
                Ve_thucthe ve_tt = new Ve_thucthe();
                ve_tt.MaVe = int.Parse(tbl_Ve.CurrentRow.Cells[0].Value.ToString());
                ve_tt.MaHopDong = int.Parse(cbo_maHopDong.Text);
                ve_dk.suaVe(ve_tt);
                MessageBox.Show("Sửa thành công");
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Chọn mã hợp đồng");
            }
        }

        private void buttonX19_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn chắc chắn muốn xóa ?", "Vé", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                Ve_dieukhien ve_dk = new Ve_dieukhien();
                Ve_thucthe ve_tt = new Ve_thucthe();
                ve_tt.MaVe = int.Parse(tbl_Ve.CurrentRow.Cells[0].Value.ToString());
                ve_dk.xoaVe(ve_tt);
            }
            
        }

        private void buttonX17_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void NV_Load(object sender, EventArgs e)
        {
            KhachHang_dieukhien kh = new KhachHang_dieukhien();
            tbl_KhachHang.DataSource = kh.DanhSachKhachHang();
            HopDong_dieukhien hd = new HopDong_dieukhien();
            tbl_HopDong.DataSource = hd.danhSachHopDong();
            Ve_dieukhien ve = new Ve_dieukhien();
            tbl_Ve.DataSource = ve.danhSachVe();
            //cbo_maHopDong.DataSource = hd.danhSachHopDong();
            //cbo_maHopDong.DisplayMember = "maHopDong";
            //cbo_maHopDong.ValueMember = "maHopDong";
        }

        private void tbl_Ve_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;
            if (dong > 0 & dong < (tbl_Ve.RowCount - 1))
            {
                cbo_maHopDong.Text =tbl_Ve.Rows[dong].Cells[1].Value.ToString();
            }
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {

            Ve_dieukhien ve_dk = new Ve_dieukhien();
            KhachHang_thucthe kh_tt = new KhachHang_thucthe();
            kh_tt.TenKhachHang = txt_timVe.Text.Trim();
            ve_dk.timVe(kh_tt);
        }

        private void buttonX11_Click(object sender, EventArgs e)
        {

        }

        private void buttonX10_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
